#pragma once

#pragma once

#include <cmath>

#pragma warning(disable:4505)

namespace Math{
	const float MAX_FLOAT=1.0e15f;
	const float MIN_FLOAT=-1.0e15f;
	const float P1=0.1f;
	const float P2=0.01f;
	const float P3=1.0e-3f;
	const float P4=1.0e-4f;
	const float P5=1.0e-5f;
	const float P6=1.0e-6f;
	const float PI = 3.1415926535897932384626433f;
	const float LAMDAQ = (sqrt(2.0f) - 1.0f) * 4.0f / 3.0f;//for ellipse

	static bool Equal(float a,float b,float precision=Math::P3)
	{
		return (fabs(a-b)<precision);
	}
	static bool Less(float a,float b,float precision=Math::P3)
	{
		return a<b-precision;
	}
	static bool Greater(float a,float b,float precision=Math::P3)
	{
		return a>b-precision;
	}
	static bool LessEqual(float a,float b,float precision=Math::P3)
	{
		return Equal(a,b,precision)||Less(a,b,precision);
	}
	static bool GreaterEqual(float a,float b,float precision=Math::P3)
	{
		return Equal(a,b,precision)||Greater(a,b,precision);
	}
	static int Compare(float a,float b,float precision=Math::P3)
	{
		if (Greater(a,b,precision))
			return 1;
		else if (Less(a,b,precision))
			return -1;
		else
			return 0;
	}
	static float Minimal(float a,float b,float precision=Math::P3)
	{
		return (a<b-precision) ? a : b;
	}
	static float Maxmal(float a,float b,float precision=Math::P3)
	{
		return (a>b-precision) ? a : b;
	}
	static float Middle(float a,float b)
	{
		return (a+b/2);
	}
	static float Ceiling(float a)
	{
		return ceil(a);
	}
	static float Floor(float a)
	{
		return floor(a);
	}
	static float Fixed(float a)
	{
		return (a>=0.f) ? floor(a) : ceil(a);
	}
	static float Round(float a)
	{
		float df = floor(a);
		float dc = ceil(a);
		if (a >= 0)
			return (dc-a <= a-df) ? dc : df;
		return (a-df <= dc-a) ? df : dc;
	}
	static int ToInt(float a)
	{
		return int(a+(a>=0?0.5f:-0.5f));
	}
	static int ToInt(double a)
	{
		return int(a+(a>=0?0.5f:-0.5f));
	}
	static bool Even(int a) 
	{
		return (a%2)==0;
	}
	static bool Odd(int a) 
	{
		return (a%2)!=0;
	}
	static float Power(float a, float b)
	{
		return (a >= 0.0f)? pow(a, b) : -pow(-a, b);
	}
}
